package com.hd.netty.server;

/**
 * @Author: hzhh123
 * @Date: 2018/12/16 16:11
 * 推送方法单独抽象出来
 */

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.channel.group.ChannelGroup;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;


/**
 * 发消息方式 抽象出来
 *
 * */
public abstract class BaseWebSocketServerHandler extends SimpleChannelInboundHandler<Object> {


    /**
     * 推送单个
     *
     * */
    public static final void push(final ChannelHandlerContext ctx,final String message){
        TextWebSocketFrame tws = new TextWebSocketFrame(message);
        ctx.channel().writeAndFlush(tws);

    }
    /**
     * 群发
     *
     * */
    public static final void push(final ChannelGroup ctxGroup,final String message){
        TextWebSocketFrame tws = new TextWebSocketFrame(message);
        ctxGroup.writeAndFlush(tws);

    }
}